#include "kzfqgraphicsview.h"
#include "QDebug"

kzfQGraphicsView::kzfQGraphicsView(QWidget *parent)
    : QGraphicsView{parent}
{



}

kzfQGraphicsView::kzfQGraphicsView(QGraphicsScene *scene, QWidget *parent)
    : QGraphicsView{scene, parent}
{



}

//------------------鼠标事件--------------------------------------------------
void kzfQGraphicsView::mousePressEvent(QMouseEvent *event)      //事件过滤器
{
    //如果鼠标左键按下
    if (event->type() == QEvent::MouseButtonPress) {
        //获取鼠标在事件接收者中的位置pos
        if(event->button() == Qt::MouseButton::LeftButton){
            emit SmouseLeftPress(event);
        }else if(event->button() == Qt::MouseButton::RightButton){
            emit SmouseRigthPress(event);
        }
    }
    QGraphicsView::mousePressEvent(event);
}

void kzfQGraphicsView::mouseReleaseEvent(QMouseEvent *event)        //事件过滤器
{
    //如果鼠标左键按下
    if (event->type() == QEvent::MouseButtonRelease) {
        //获取鼠标在事件接收者中的位置pos
        emit SmouseRelease(event);
    }
    QGraphicsView::mouseReleaseEvent(event);
}

void kzfQGraphicsView::mouseMoveEvent(QMouseEvent *event)        //事件过滤器
{
    QGraphicsView::mouseMoveEvent(event);//需要加这个  不然上面的控件无法响应这个动作
    emit SmouseMove(event);

    // qDebug() <<"gv mouse move"<<event->pos();
    // emit SmouseMove(event);
    // qDebug() << this->geometry().x();
    // qDebug() << this->geometry().y();
    // QPoint sPoint1=event->globalPos();
    // qDebug()<<"相对于屏幕坐标1:"<<"("<<sPoint1.rx()<<","<<sPoint1.ry()<<")";
    // QPoint sPoint2=QCursor::pos();
    // qDebug()<<"相对于屏幕坐标2:"<<"("<<sPoint2.rx()<<","<<sPoint2.ry()<<")";
    // QPoint windowPoint=this->mapFromGlobal(sPoint2);
    // qDebug()<<"相对于窗口坐标:"<<"("<<windowPoint.rx()<<","<<windowPoint.ry()<<")";
    // QPoint widgetPoint=ui->L_img->mapFromGlobal(sPoint1);
    // qDebug()<<"相对于控件坐标:"<<"("<<widgetPoint.rx()<<","<<widgetPoint.ry()<<")";
}
//====================================================================================

// void kzfQGraphicsView::enterEvent(QEvent *event)        //事件过滤器
// {
//     // qDebug() <<"____________________mouse enterEvent";
// }

// void kzfQGraphicsView::leaveEvent(QEvent *event)        //事件过滤器
// {
//     // qDebug() <<"(((((((((((((((mouse leaveEvent";
// }

